<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all"/>
    <script type="text/javascript" th:src="@{/js/jquery-3.2.1.js}"></script>
    <script th:src="@{/layui/layui.js}" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/css/TeaSelect.css}"/>
    <!--<script type="text/javascript" th:src="@{/js/TeaSelect.js}"></script>-->
</head>
<body>
<!--轮播图片-->
<div class="layui-carousel" id="test1">
    <div carousel-item="">
        <div><img src="image/lun.jpg" width="100%" height="100%"/></div>
        <div><img src="image/lun2.jpg" width="100%" height="100%"/></div>
        <div><img src="image/13.jpg" width="100%" height="120%"/></div>
    </div>
</div>
<script>
    layui.use('carousel', function () {
        var carousel = layui.carousel;
        //建造实例
        carousel.render({
            elem: '#test1'
            , width: '100%' //设置容器宽度
            , arrow: 'none' //始终显示箭头
            , width: '1080px'
            , height: '150px'
            //,anim: 'updown' //切换动画方式
        });
    });
</script>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend><span class="" style="font-size: 14px">
        <a href="/dor/indexdemo">首页<span class="layui-box">&gt;</span></a>
  <span>人员管理<span class="layui-box">&gt;</span></span>
  <span>宿管管理<span class="layui-box">&gt;</span></span>
</span>
    </legend>
</fieldset>
<div style="position:relative; left: 10px">
        <input class="layui-btn layui-btn-normal" type="button" value="添加一名宿管信息" onClick="location.href='http://127.0.0.1:8080/dor/addTea'" />

</div>

<table class="layui-table" lay-data="{width: 1300, height:0, url:'/dor/tea', page:true, id:'idTest'}" lay-filter="demo">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
        <th lay-data="{field:'tea_id', width:90, sort: true, fixed: true}">ID</th>
        <th lay-data="{field:'name', width:120}">姓名</th>
        <th lay-data="{field:'sex', width:100}">性别</th>
        <th lay-data="{field:'phone', width:180}">手机号码</th>
        <!--<th lay-data="{field:'job', width:80}">职位</th>-->
   <!--     <th lay-data="{field:'email', width:180, sort: true}">电子邮箱</th>-->
        <th lay-data="{fixed: 'right', width:230, align:'center', toolbar: '#barDemo'}"></th>
    </tr>
    </thead>
</table>



<div class="look_div" hidden="hidden" id="look_div">
    <div class="layui-layer-title" style="cursor: move;">宿管详情</div>
    <div class="layui-layer-setwin" ><a class="layui-layer-ico layui-layer-close layui-layer-close1 out_bg"  href="javascript:;"></a></div>
    <br/>
    <form class="layui-form layui-form-pane" action="" id="teaForm" method="put" style="position: relative;left: 50px;">
        <div  class="layui-anim layui-anim-scale">
            <!--<div style="display: flex;align-items: center;">-->
                <div class="layui-form-item">
                    <label class="layui-form-label">宿管编号</label>
                    <div class="layui-input-inline">
                        <input type="text" id="teaid" name="tea_id" autocomplete="off" placeholder="请输入编号" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" id="teaname" placeholder="请输入姓名" autocomplete="off" class="layui-input"/>
                    </div>
                </div>
            <!--</div>-->
            <!--<div style="display: flex;align-items: center;">-->
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="password" id="teapassword" placeholder="请输入密码" autocomplete="off"
                               class="layui-input"/>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-inline" >
                        <!-- <input type="radio" id="nan"  name="sex" value="男" title="男"  />
                         <input type="radio" class="nv" name="sex" value="女" title="女" />-->
                        <!--<select name="sex" id="sex" >
                            <option value="男">男</option>
                            <option value="女">女</option>
                        </select>-->
                        <input type="text" name="sex" id="sex" autocomplete="off" class="layui-input"/>
                    <!--    <select name="sex" id=""  lay-verify="">
                            <option value="1" id="sex" ><span id="sex1"></span></option>
                            <option value="男">男</option>
                            <option value="女">女</option>
                        </select>-->

                    </div>
                </div>
            <!--</div>-->

            <!--<div style="display: flex;align-items: center;">-->
                <div class="layui-form-item">
                    <label class="layui-form-label">手机号码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="phone" id="teaphone" placeholder="请输入手机号码" autocomplete="off" class="layui-input"/>
                    </div>
                </div>
              <!--  <div class="layui-form-item">
                    <label class="layui-form-label">身份证</label>
                    <div class="layui-input-block">
                        <input type="text" name="idcard" id="teaidcard" placeholder="请输入身份证" autocomplete="off"
                               class="layui-input"/>
                    </div>
                </div>-->
            <!--</div>-->

            <!--<div style="display: flex;align-items: center;">
                <div class="layui-form-item">
                    <label class="layui-form-label">职位</label>
                    <div class="layui-input-block">
                        <input type="text" name="job" id="teajob" placeholder="请输入手机" autocomplete="off"
                               class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">办公电话</label>
                    <div class="layui-input-block">
                        <input type="text" name="tel" id="teatel" autocomplete="off" class="layui-input"/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电子邮箱</label>
                <div class="layui-input-inline">
                    <input type="text" name="email" id="teaemail"  autocomplete="off"
                           class="layui-input"/>
                </div>
            </div>-->

            <div class="layui-form-item">
                <button class="layui-btn" type="button" lay-filter="demo2" onclick="gexing()">更新</button>
            </div>
        </div>
    </form>
</div>

<div class="out_bg" hidden="hidden"></div>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-normal layui-btn-mini" lay-event="detail" onclick="look()">查看编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
   <!-- <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" onclick="look()">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<script>
    /*<![CDATA[*/
    var id ;
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
        });

            //监听工具条
            table.on('tool(demo)', function (obj) {
                var data = obj.data;
                id = data.tea_id;
                if (obj.event === 'detail') {
                    console.log(data.tea_id);
                    $('#teaid').val(obj.data.tea_id);
                    $('#teaname').val(obj.data.name);
                    $('#sex').val(obj.data.sex);
                    $('#sex1').val(obj.data.sex);
                    $('#teapassword').val(obj.data.password);
                    $('#teaphone').val(obj.data.phone);
                    $('#teaidcard').val(obj.data.IDcard);
                    $('#teajob').val(obj.data.job);
                    $('#teatel').val(obj.data.tel);
                    $('#teaemail').val(obj.data.email);
                    //layer.msg('ID：' + data.tea_id + ' 的查看操作');
                } else if (obj.event === 'del') {
                    layer.confirm('确认删除该老师信息', function (index) {
                        $.ajax({
                            type: "DELETE",
                            url: "/dor/teacher/" + obj.data.tea_id,
                            data: "{}",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (data) { // Play with response returned in JSON format
                                return true;
                            },
                            error: function (msg) {
                                return false;
                            }
                        });
                        obj.del();
                        layer.close(index);
                        // console.log('年后');

                    });
                } else if (obj.event === 'edit') {
                    layer.alert('编辑行：<br/>' + JSON.stringify(data))
                }

            });

        $('.out_bg').click(function () {
            $('.out_bg').hide();
            $('#look_div').hide();
        });


        });



</script>
<script>
    function gexing() {
        var tea= new FormData($("#teaForm")[0]);
        /*for (var [key, value] of tea.entries()) {
            console.log(key, value);
        }*/
        /*var objData = {};

        for (var entry of tea.entries()){
            objData[entry[0]] = entry[1];
        }*/
        var list = $("#teaForm").serializeArray();
        var objData = {};
        for (var i = 0; i < list.length; i++) {
            objData[list[i].name] = list[i].value;
        }
        var date = JSON.stringify(objData);
        $.ajax({
            url: "/dor/tea/update",
            type: "post",
            data: date,
            async: false,
            cache: false,
            processData: false,
            contentType: "application/json; charset=utf-8",
            success: function (data) { // Play with response returned in JSON format
                if (data) {
                    window.location.reload(true);
                }
            },
            error: function (msg) {
                return false;
            }
        });
    }
    /*]]>*/
</script>
<script type="text/javascript" th:src="@{/js/TeaSelect.js}"></script>
</body>
</html>